// 文件: services/user_service.go
package services

import (
    "iris-mvc/models"
    "iris-mvc/repositories"
)

type UserService interface {
    GetAll() []models.User
    GetByID(id int64) (models.User, bool)
    // DeleteByID(id int64) bool
    // UpdatePosterAndGenreByID(id int64, poster string, genre string) (models.User, error)
}
// NewUserService返回默认的user service
func NewUserService(repo repositories.UserRepository) UserService {
    return &userService{
        repo: repo,
    }
}
type userService struct {
    repo repositories.UserRepository
}
// GetAll返回所有
func (s *userService) GetAll() []models.User {
    return s.repo.SelectMany(func(_ models.User) bool {
        return true
    }, -1)
}
// GetByID根据其id返回一部电影
func (s *userService) GetByID(id int64) (models.User, bool) {
    return s.repo.Select(func(m models.User) bool {
        return m.ID == id
    })
}
// func (s *userService) UpdatePosterAndGenreByID(id int64, poster string, genre string) (models.User, error) {
//     return s.repo.InsertOrUpdate(models.User{
//         ID:     id,
//         Poster: poster,
//         Genre:  genre,
//     })
// }
//如果删除则返回true，否则返回false。
// func (s *userService) DeleteByID(id int64) bool {
//     return s.repo.Delete(func(m models.User) bool {
//         return m.ID == id
//     }, 1)
// }